<template>
  <div class="flex flex-col h-full">
    <SearchContainer @search="getData" @reset="() => formRef.resetFields()">
      <a-form ref="formRef" class="form-style-flex" :model="formState" :label-col="{ style: { width: '70px' } }">
        <a-form-item name="dateRange" label="入院日期" class="w-80 mr-5">
          <a-range-picker v-model:value="formState['dateRange']" format="YYYY-MM-DD" value-format="YYYY-MM-DD" />
        </a-form-item>
        <a-form-item name="pyjm" label="" class="w-1/4">
          <a-input v-model:value="formState.pyjm" placeholder="姓名/助记码/住院号/手机号/身份证号" />
        </a-form-item>
      </a-form>
    </SearchContainer>
    <a-card class="mt-2 flex-1">
      <div class="flex justify-end mb-2">
        <BaseExport type="住院" name="住院检索" code="000407" :search-params="formState">导出</BaseExport>
      </div>
      <BaseTable fill :loading="loading" column-code="000407" :data-source="tableData" bordered :pagination="pagination">
        <template #bodyCell="{ column, index, record }">
          <template v-if="column.dataIndex === 'xh'">
            {{ index + 1 }}
          </template>
          <template v-if="column.dataIndex === 'status'">
            <a-tag v-if="record.status === 0" color="blue">在院</a-tag>
            <a-tag v-if="record.status === 1" color="green">已出院</a-tag>
            <a-tag v-if="record.status === 2" color="orange">待出院</a-tag>
            <a-tag v-if="record.status === 3" color="purple">待入区</a-tag>
            <a-tag v-if="record.status === 4" color="red">作废</a-tag>
          </template>
          <template v-if="column.dataIndex === 'action'">
            <a-button type="link" size="small" @click="onClickRecord(record)"> 流转记录 </a-button>
          </template>
        </template>
      </BaseTable>
    </a-card>
    <Edit v-model:open="open" :row-data="rowData" />
  </div>
</template>

<script setup>
import { ref, onMounted, reactive } from 'vue'
import dayjs from 'dayjs'
// import { message } from 'ant-design-vue'
import SearchContainer from '@/components/SearchContainer'
// import { post } from '@/utils/request'
import Edit from './Edit'

const open = ref(false)
const formRef = ref(null)
const rowData = ref({})
const formState = reactive({
  dateRange: [dayjs().format('YYYY-MM-DD'), dayjs().format('YYYY-MM-DD')]
})
const { loading, pagination, tableData, getData } = useTable({
  url: '/inp/zydj/getInpRecordList',
  formatParams: () => {
    return {
      stdate: formState.dateRange?.[0],
      eddate: formState.dateRange?.[1],
      pyjm: formState?.pyjm
    }
  }
})

const onClickRecord = (row) => {
  open.value = true
  rowData.value = { ...row }
}

onMounted(() => {
  getData()
})
</script>
<style lang="less" scoped>
.ant-picker {
  width: 100%;
}
</style>
